var t = function(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}(require("../../utils/api2")), e = require("../../utils/style-utils"), s = void 0, a = void 0;

Component({
    properties: {
        sidebarReady: {
            type: Boolean,
            observer: function(t) {
                t && this.tryInit();
            }
        },
        mode: {
            type: String,
            observer: function(t) {
                this.setData({
                    show: "edit" !== t
                });
            }
        },
        isListSetting: {
            type: Boolean,
            observer: function(t) {
                this.setData({
                    show: !t
                });
            }
        }
    },
    data: {
        sid: "",
        show: !0,
        tabList: [],
        mobile: "",
        address: "",
        latitude: "",
        longitude: "",
        isfocus: !1,
        isTabListEmpty: !1,
        isTabListLoading: !0
    },
    ready: function() {
        var e = this, i = getCurrentPages(), n = getApp().globalData.sid;
        s = i[i.length - 1], a = [], t.default.site.tab.lists({
            data: {
                sid: s.__query.sid || n
            }
        }).then(function(t) {
            a = t.sort(function(t, e) {
                return t.sort - e.sort;
            }), e.tryInit();
        });
    },
    methods: {
        tryInit: function() {
            var t = this;
            if (a = a || [], this.setData({
                isTabListEmpty: 0 === a.length
            }), a.length && this.data.sidebarReady) {
                var i = s.data.sidebar, n = i.site, r = i.navs;
                a.forEach(function(e) {
                    switch (e.type) {
                      case "nav":
                        var a = r.find(function(t) {
                            return e.navid === +t.navid;
                        });
                        if (a) {
                            e.url = a.navUrl;
                            var i = s.__query.navid;
                            e.active = i ? e.navid === +i : -1 !== e.url.search(s.route);
                        }
                        break;

                      case "mobile":
                        t.setData({
                            mobile: n.tel
                        });
                        break;

                      case "map":
                        t.setData({
                            address: n.address,
                            latitude: n.addresslat,
                            longitude: n.addresslng
                        });
                        break;

                      case "members":
                        e.url = "/pages/profile-entry/members/members?sid=" + n.sid, e.active = "pages/profile-entry/members/members" === s.route;
                        break;

                      case "cart":
                        e.url = "/pages/common/shopping-cart/shopping-cart?origin=tab&sid=" + n.sid + "&app=" + n.app + "&mchid=" + n.mchid, 
                        e.active = "pages/common/shopping-cart/shopping-cart" === s.route;
                        break;

                      case "focus":
                        t.setData({
                            sid: n.sid,
                            isfocus: n.isfocus
                        }), e.active = n.isfocus;
                        break;

                      case "payment":
                        e.url = "/pages/common/payment/payment?sid=" + n.sid, e.active = "pages/common/payment/payment" === s.route;
                        break;

                      case "classify":
                        e.url = "/pages/common/classify/view/view?sid=" + n.sid + "&title=" + e.title, e.active = "pages/common/classify/view/view" === s.route;
                    }
                }), this.setData(Object.assign({
                    tabList: a,
                    isTabListLoading: !1
                }, (0, e.formatTabColor)(n.style.tab))), s.setData({
                    isInitTabList: a.length > 0
                });
            }
        },
        informNotExist: function(e) {
            var a = this, i = e.currentTarget.dataset.id;
            ("isedit" in this.data ? Promise.resolve(this.data.isedit) : t.default.site.site.view({
                data: {
                    sid: s.__query.sid
                }
            }).then(function(t) {
                var e = t.isedit;
                return a.setData({
                    isedit: e
                }), e;
            })).then(function(t) {
                t ? wx.showModal({
                    title: "链接已失效",
                    content: "栏目已被删除，请前往Tab设置重新设置链接",
                    success: function(t) {
                        t.confirm && wx.redirectTo({
                            url: "/pages/website/settings/tab-config/tab-config?sid=" + s.__query.sid + "&id=" + i
                        });
                    }
                }) : wx.showModal({
                    title: "链接失效",
                    content: "该栏目已被删除",
                    showCancel: !1
                });
            });
        },
        makeCall: function() {
            wx.makePhoneCall({
                phoneNumber: this.data.mobile
            });
        },
        map: function() {
            var t = this.data, e = t.address, s = t.latitude, a = t.longitude;
            wx.openLocation({
                address: e,
                latitude: s,
                longitude: a
            });
        },
        setFocus: function(e) {
            var s = this, a = this.data, i = a.tabList, n = a.isfocus, r = a.sid, o = e.currentTarget.dataset.index, d = i[o], c = n ? "cancel" : "add";
            t.default.site.focus.set({
                data: {
                    sid: r,
                    op: c
                },
                desc: "关注操作"
            }).then(function() {
                d.active = !n, s.setData({
                    tabList: i,
                    isfocus: !n
                });
            });
        },
        goto: function(t) {
            wx.redirectTo({
                url: t.currentTarget.dataset.url
            });
        }
    }
});